//
//  CantonDetailView.m
//  WRY
//
//  Created by zhong sckj on 10-10-14.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CantonDetailView.h"
#import "AppDelegate_iPad.h"


@implementation CantonDetailView
@synthesize dataArray;
@synthesize detailTextView;

- (id)initWithFrame:(CGRect)frame initArrayData:(NSMutableArray *)array {
    if ((self = [super initWithFrame:frame])) {
		self.dataArray=array;
		detailTextView=[[UITextView alloc]initWithFrame:CGRectMake(5, 5,780,150)];
		detailTextView.userInteractionEnabled=NO;
		[self addSubview:detailTextView];
		[detailTextView release];
		[self setSummaryText];
    }
    return self;
}
- (void)setSummaryText {
	
    
    
	NSDictionary *directFeiShui=nil;
	NSDictionary *directFeiqi=nil;
	NSDictionary *directWushui=nil;
	NSDictionary *directTotal=nil;
    NSDictionary *directMetal=nil;//重金属
	for (int i=0; i<[dataArray count]; i++) {
		NSString *enterpriseType=[(NSDictionary *)[dataArray objectAtIndex:i] objectForKey:@"DetailTypeCode"];
		NSDictionary *direct=(NSDictionary *)[dataArray objectAtIndex:i];
		if ([enterpriseType isEqualToString:@"01"]) {
			//废水
			directFeiShui=direct;
		}
		else if([enterpriseType isEqualToString:@"02"])
		{
			directFeiqi=direct;
		}
		else if([enterpriseType isEqualToString:@"03"])
		{
			directWushui=direct;
		}
        else if([enterpriseType isEqualToString:@"04"])
		{
			directMetal=direct;
		}
		else if([enterpriseType isEqualToString:@""]){
			directTotal=direct;
		}
	}
	NSMutableString *body = [[NSMutableString alloc] init];
	[body appendFormat:@"      %@共有污染源%@个,",[[AppDelegate_iPad currentDelegate] showCantonName],[directTotal objectForKey:@"EnterpriseCount"]];
	[body appendFormat:@"其中%@个废水污染源,",[directFeiShui objectForKey:@"EnterpriseCount"]];
	[body appendFormat:@"%@个废气污染源,",[directFeiqi objectForKey:@"EnterpriseCount"]];
	if (directWushui!=nil) {
		[body appendFormat:@"%@个污水处理厂,",[directWushui objectForKey:@"EnterpriseCount"]];
	}
    if (directMetal!=nil) {
		[body appendFormat:@"%@个重金属。",[directMetal objectForKey:@"EnterpriseCount"]];
	}
	NSString *userType=[[AppDelegate_iPad currentDelegate] userType];
    NSString *tempStr=@"全省";
    if (userType !=nil && [userType isEqualToString:@"1"]) {
        tempStr=@"全市";
    }
    else if(userType !=nil && [userType isEqualToString:@"2"])
    {
         tempStr=@"全区";
    }
	[body appendFormat:@"根据最新监测数据显示,目前%@超标污染源共%@个,",tempStr,[directTotal objectForKey:@"SuperscaleCount"]];
	[body appendFormat:@"其中废水%@个,",[directFeiShui objectForKey:@"SuperscaleCount"]];
	[body appendFormat:@"废气%@个,",[directFeiqi objectForKey:@"SuperscaleCount"]];
	if (directWushui!=nil) {
		[body appendFormat:@"污水处理厂%@个,",[directWushui objectForKey:@"SuperscaleCount"]];
	}
    if (directMetal!=nil) {
		[body appendFormat:@"重金属%@个,",[directMetal objectForKey:@"SuperscaleCount"]];
	}
	[body appendFormat:@"故障或停产污染源共%@个。",[directTotal objectForKey:@"TroubleCount"]];
	detailTextView.text = body;
	detailTextView.font=[UIFont systemFontOfSize:22.0f];
	[body release];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc {
	[detailTextView release];
	[dataArray release];
    [super dealloc];
}


@end
